using System;
using System.Collections.Generic;
using Lucene.Net.Store;
using Directory=Lucene.Net.Store.Directory;

namespace LuceneSearch.ContactApp.Indexing
{
    public class IndexDirectoryProvider
    {
        private readonly Dictionary<Type, Directory> typeToIndexDirectory = new Dictionary<Type, Directory>();

        public Directory GetIndexDirectoryForType(Type type)
        {
            if (!typeToIndexDirectory.ContainsKey(type))
                typeToIndexDirectory.Add(type, CreateDirectory(type));

            return typeToIndexDirectory[type];
        }

        private static Directory CreateDirectory(Type type)
        {
            // just use ram for demo
            return new RAMDirectory();

//            var path = "index\\" + type.Name;
//            var exists = System.IO.Directory.Exists(path);
//            return FSDirectory.GetDirectory(path, !exists);
        }
    }
}